(function () {
    var exports = this;
    var $ = null;
    exports.ClubEditScore = cc.Layer.extendEX({
        _isSelectedMaxScore: false,    // 菜单中 是否选中大赢家选项
        _recordData: [],               // http请求到的自己的战绩
        _viewUseRecordData: [],        // 显示时使用的战绩信息 (条件过滤后 也会给这个变量赋值)
        ctor: function (callBack) {
            this._super();
            loadNodeCCS(res.ClubEditScore_json, this, false);
            $ = create$(this.getChildByName('Node'));
            this.getChildByName('Node').getChildByName('modalLayer').setTouchEnabled(false);
            this.getChildByName('Node').getChildByName('modalLayer').setSwallowTouches(false);

            this._callBack = callBack;
            this._contentStr = "";
            this._refreshContent();
            this._initTouchEvent();
        },

        _initTouchEvent: function () {
            for (var i = 0; i <= 9; i++) {
                var btn = $('btn_' + i);
                btn.index = i;
                TouchUtil.setOnclickListener(btn, this._numSelectedHandler.bind(this));
            }
            TouchUtil.setOnclickListener($('btn_ok'), this._okBtnHandler.bind(this));
            TouchUtil.setOnclickListener($('btn_clear'), this._clearBtnHandler.bind(this));
            TouchUtil.setOnclickListener($('btn_del'), this._delBtnHandler.bind(this));
            TouchUtil.setOnclickListener($('btn_closePanel'), this.closePanelHandler.bind(this));
        },

        _numSelectedHandler: function (target) {
            var str = this._contentStr;
            this._contentStr += target.index;
            if (!this._refreshContent()) {
                this._contentStr = str;
            }


        },

        _okBtnHandler: function () {
            if (this._contentStr.length == 0 || this._contentStr == '') {
                showAlert('分数不能为空');
                return;
            }
            if (this._callBack) {
                this._callBack(this._contentStr);
            }
            this.removeFromParent();
        },

        _clearBtnHandler: function () {
            this._contentStr = "";
            this._refreshContent();
        },

        _delBtnHandler: function () {
            this._contentStr = this._contentStr.substring(0, this._contentStr.length - 1);
            this._refreshContent();
        },
        _refreshContent: function () {
            if (this._contentStr.length > 5) {
                showAlert("最大分数上线5位分数");
                return false;
            }
            $('contentLabel').setString(this._contentStr);
            return true;
        },

        closePanelHandler: function () {
            this.removeFromParent();
        }
    });

    exports.ClubEditScore = ClubEditScore;
})(window);